
// Copyright (C) Recursion Company. All rights reserved.

#include "stdafx.h"
#include "vol_user_app_info.h"

//-----------------------------------------------------------------------------------------

BOOL CVWnd_HotKey::CreateControl (CVolNativeWndCreateParam* pCreateParam)
{
    return (_CREATE_WND_BY_PARAM (pCreateParam) != NULL);
}

UINT_P CVWnd_HotKey::sVolKeyModifiers2HotCtrl (UINT_P upVolKeyModifier)
{
    UINT_P upModifiers = 0;
    if ((upVolKeyModifier & KYS_CONTROL) != 0)  upModifiers |= HOTKEYF_CONTROL;
    if ((upVolKeyModifier & KYS_SHIFT) != 0)  upModifiers |= HOTKEYF_SHIFT;
    if ((upVolKeyModifier & KYS_ALT) != 0)  upModifiers |= HOTKEYF_ALT;

    return upModifiers;
}

UINT_P CVWnd_HotKey::sHotCtrlKeyModifiers2Vol (UINT_P upHotCtrlKeyModifier)
{
    UINT_P upModifiers = 0;
    if ((upHotCtrlKeyModifier & HOTKEYF_CONTROL) != 0)  upModifiers |= KYS_CONTROL;
    if ((upHotCtrlKeyModifier & HOTKEYF_SHIFT) != 0)  upModifiers |= KYS_SHIFT;
    if ((upHotCtrlKeyModifier & HOTKEYF_ALT) != 0)  upModifiers |= KYS_ALT;

    return upModifiers;
}

INT CVWnd_HotKey::GetCurrentHotKey ()
{
    if (m_hWnd == NULL)
        return KYV_NULL;

    WORD wVirtualKeyCode = 0, wModifiers = 0;
    GetHotKey (wVirtualKeyCode, wModifiers);

    UINT_P upKeyCode = GetKeyCodeFromVirtualKey ((UINT_P)(DWORD)wVirtualKeyCode);
    if (upKeyCode != KYV_NULL)
        upKeyCode |= sHotCtrlKeyModifiers2Vol ((UINT_P)(DWORD)wModifiers);

    return (INT)upKeyCode;
}

void CVWnd_HotKey::SetCurrentHotKey (INT nKeyCode)
{
    if (m_hWnd != NULL)
        SetHotKey ((WORD)(nKeyCode & KYM_MASK), (WORD)sVolKeyModifiers2HotCtrl (nKeyCode));
}

void CVWnd_HotKey::SetInvalidHotKeyModifiers (INT nInvalidModifiers, INT nReplaceModifiers)
{
    nInvalidModifiers &= (KYS_CONTROL | KYS_SHIFT | KYS_ALT);

    WORD wInvalidComb;
    switch (nInvalidModifiers)
    {
    case KYS_CONTROL:                         wInvalidComb = HKCOMB_C;    break;
    case KYS_SHIFT:                           wInvalidComb = HKCOMB_S;    break;
    case KYS_ALT:                             wInvalidComb = HKCOMB_A;    break;
    case (KYS_SHIFT | KYS_CONTROL):           wInvalidComb = HKCOMB_SC;   break;
    case (KYS_CONTROL | KYS_ALT):             wInvalidComb = HKCOMB_CA;   break;
    case (KYS_SHIFT | KYS_ALT):               wInvalidComb = HKCOMB_SA;   break;
    case (KYS_SHIFT | KYS_CONTROL | KYS_ALT): wInvalidComb = HKCOMB_SCA;  break;
    default:                                  wInvalidComb = HKCOMB_NONE; break;
    }

    SetRules (wInvalidComb, (WORD)sVolKeyModifiers2HotCtrl ((UINT_P)nReplaceModifiers));
}
